#include <bits/stdc++.h>
using namespace std;
struct node{
    int d , v , a;
}c[1000005];
bool cmp(int a , int b){
    return a > b;
}
int main(){
    freopen("detect.in" , "r" , stdin);
    freopen("detect.out" , "w" , stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while(T--){
        int n , m , L , V , tmp , sum = 0;
        int a[1000005] = {};
        cin >> n >> m >> L >> V;
        for(int i = 1 ; i <= n ; i++){
            cin >> c[i].d >> c[i].v >> c[i].a;
        }
        for(int i = 1 ; i <= m ; i++) cin >> a[i];
        sort(a + 1 , a + m + 1 , cmp);
        for(int i = 1 ; i <= n ; i++){
            if(c[i].v > V && c[i].d <= a[1]) sum++;
        }
        if(sum == 0) cout << sum << " " << m << endl;
        else cout << sum << " " << m - 1 << endl;
    }
    return 0;
}
